package com.cacho.s2b.lesson.learn;

import jakarta.xml.bind.DatatypeConverter;

/**
 * @Description jakarta.xml.bind-api 各种常见数据类型转换
 * @Author LingWei
 * @date 2023/12/26
 **/

public class LearnXmlBind {
    public static void main(String args[]) {
        byte[] byteArray = {1, 2, 3, 4, 5};
        String base64String = DatatypeConverter.printBase64Binary(byteArray);
        System.out.println("字节数组转换为base64字符串：" + base64String);
        System.out.println("base64字符串转换为字节数组：" + DatatypeConverter.parseBase64Binary(base64String));

        String swiftBic = "SCBLGB2LXX";
        String iban = "";
        String number = "000044249215601";
        String currency = "GBP";
        String dd = DatatypeConverter.printHexBinary((number + ":" + currency + ":" + blankIfNull(iban)).getBytes());
        System.out.println("表示十六进制编码的二进制数据hexaBinary：" + dd);
    }

    public static String blankIfNull(String swiftBic) {
        return swiftBic == null ? "" : swiftBic;
    }
}